package org.melanesia.sql;

import org.melanesia.converters.JavaToJavaConverter;

/**
 * Output parameter metadata.
 *
 * @author marcin.kielar
 *
 */
class OutputParameter {

    /** Parameter name. */
    private final String name;

    /** Parameter class. */
    private final Class<?> parameterClass;

    /**
     * Optional, explicitly set jdbc type. If not set, the type will be determined
     * by looking up for a JavaToJdbcConverter for the {@link #parameterClass}.
     */
    private final Integer jdbcType;

    /**
     * Optional, explicitly set database type name for user-defined database types.
     * For simple types like VARCHAR, NUMERIC, DATE etc. there is no need to pass this.
     */
    private final String databaseTypeName;

    /**
     * Optional, explicitly set java to java converter. If not set, the
     * converter will be looked up in {@link org.melanesia.converters.TypeConverter}.
     */
    private final JavaToJavaConverter converter;

    /**
     * Constructs new <code>OutputParameter</code>.
     *
     * @param name
     *            parameter name
     * @param parameterClass
     *            parameter class
     */
    OutputParameter(final String name, final Class<?> parameterClass) {
        this(name, parameterClass, null, null, null);
    }

    /**
     * Constructs new <code>OutputParameter</code>.
     *
     * @param name
     *            parameter name
     * @param parameterClass
     *            parameter class
     * @param jdbcType
     *            explicitly set jdbc type
     * @param databaseTypeName
     *            explicitly set database type name for user-defined database
     *            types
     * @param converter
     *            java to java converter
     */
    OutputParameter(final String name, final Class<?> parameterClass, final Integer jdbcType, final String databaseTypeName,
            final JavaToJavaConverter converter) {
        this.name = name;
        this.parameterClass = parameterClass;
        this.jdbcType = jdbcType;
        this.databaseTypeName = databaseTypeName;
        this.converter = converter;
    }

    /**
     * Returns parameter name.
     *
     * @return parameter name
     */
    final String getName() {
        return name;
    }

    /**
     * Returns parameter type.
     *
     * @return parameter type
     */
    final Class<?> getParameterClass() {
        return parameterClass;
    }

    /**
     * Returns the explicitly set jdbc type for this parameter value.
     * @return jdbc type
     */
    final Integer getJdbcType() {
    	return jdbcType;
    }

    /**
     * Returns the explicitly set database type name for user-defined database types.
     * @return database type name
     */
    final String getDatabaseTypeName() {
    	return databaseTypeName;
    }

    /**
     * Returns the explicitly set converter for this parameter value.
     *
     * @return java to java converter
     */
    final JavaToJavaConverter getConverter() {
        return converter;
    }
}
